
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2023/05/01
// Design Name:
// Module Name: tbm_top
// Project Name: wujian100
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// base ahb addr is 0x3000_0000  none offset
//////////////////////////////////////////////////////////////////////////////////

module tbm_top
    (//与允许读写权限从机端口相连的
    input                              tbm_a_clk_i,
    input                              tbm_a_rst_n_i,
    input                 [32 - 1 : 0] tbm_a_haddr_i,
    input                 [4  - 1 : 0] tbm_a_hprot_i,                            //hprot[0]为0，代表是来自tee的访问信号，为1，代表是来自ree的访问信号
    input                 [1  - 1 : 0] tbm_a_hsel_i,
    input                 [3  - 1 : 0] tbm_a_hsize_i,
    input                 [2  - 1 : 0] tbm_a_htrans_i,
    input                 [32 - 1 : 0] tbm_a_hwdata_i,
    input                 [1  - 1 : 0] tbm_a_hwrite_i,
    output                [32 - 1 : 0] tbm_a_hrdata_o,
    output                [1  - 1 : 0] tbm_a_hready_o,
    output                [2  - 1 : 0] tbm_a_hresp_o,
    output                [1  - 1 : 0] tbm_a_t2r_intr_o,
    //与只允许读权限从机端口相连的
    input                              tbm_b_clk_i,
    input                              tbm_b_rst_n_i,
    input                 [32 - 1 : 0] tbm_b_haddr_i,
    input                 [4  - 1 : 0] tbm_b_hprot_i,                            //hprot[0]为0，代表是来自tee的访问信号，为1，代表是来自ree的访问信号
    input                 [1  - 1 : 0] tbm_b_hsel_i,
    input                 [3  - 1 : 0] tbm_b_hsize_i,
    input                 [2  - 1 : 0] tbm_b_htrans_i,
    input                 [32 - 1 : 0] tbm_b_hwdata_i,
    input                 [1  - 1 : 0] tbm_b_hwrite_i,
    output                [32 - 1 : 0] tbm_b_hrdata_o,
    output                [1  - 1 : 0] tbm_b_hready_o,
    output                [2  - 1 : 0] tbm_b_hresp_o,
    output                [1  - 1 : 0] tbm_b_t2r_intr_o
    );
localparam ADDR_W                      = 16+3;                                 //子空间有512k的寻址空间

wire                      [1  - 1 : 0] t2r_a_clk_w;
wire                      [1  - 1 : 0] t2r_a_rst_n_w;
wire                      [1  - 1 : 0] t2r_a_en_box;
wire                      [1  - 1 : 0] t2r_a_write_box;
wire                  [ADDR_W - 1 : 0] t2r_a_addr_w;
wire                      [32 - 1 : 0] t2r_a_wdat_w;
wire                      [1  - 1 : 0] t2r_a_rdy_w;
wire                      [32 - 1 : 0] t2r_a_rdat_w;
wire                      [1  - 1 : 0] t2r_a_intr_w;

wire                      [1  - 1 : 0] t2r_b_clk_w;
wire                      [1  - 1 : 0] t2r_b_rst_n_w;
wire                      [1  - 1 : 0] t2r_b_en_box;
wire                      [1  - 1 : 0] t2r_b_write_box;
wire                  [ADDR_W - 1 : 0] t2r_b_addr_w;
wire                      [32 - 1 : 0] t2r_b_wdat_w;
wire                      [1  - 1 : 0] t2r_b_rdy_w;
wire                      [32 - 1 : 0] t2r_b_rdat_w;
wire                      [1  - 1 : 0] t2r_b_intr_w;

/************************************/
/*例化子模块                         */
/************************************/

tm_ahb_if
   #(
    .ADDR_W                            (ADDR_W                                 ),
    .MODE_SEL                          (1                                      )                   
    )
u1_tm_ahb_if
    (
    .tai_clk_i                         (tbm_a_clk_i                            ),            
    .tai_rst_n_i                       (tbm_a_rst_n_i                          ),              
    .tai_haddr_i                       (tbm_a_haddr_i                          ),              
    .tai_hprot_i                       (tbm_a_hprot_i                          ),              
    .tai_hsel_i                        (tbm_a_hsel_i                           ),             
    .tai_hsize_i                       (tbm_a_hsize_i                          ),              
    .tai_htrans_i                      (tbm_a_htrans_i                         ),               
    .tai_hwdata_i                      (tbm_a_hwdata_i                         ),               
    .tai_hwrite_i                      (tbm_a_hwrite_i                         ),               
    .tai_hrdata_o                      (tbm_a_hrdata_o                         ),               
    .tai_hready_o                      (tbm_a_hready_o                         ),               
    .tai_hresp_o                       (tbm_a_hresp_o                          ),              
    .tai_t2r_intr_o                    (tbm_a_t2r_intr_o                       ),        

    .t2r_clk_w                         (t2r_a_clk_w                            ),                  
    .t2r_rst_n_w                       (t2r_a_rst_n_w                          ),                    
    .en_box                            (t2r_a_en_box                           ),                   
    .write_box                         (t2r_a_write_box                        ),                   
    .t2r_addr_w                        (t2r_a_addr_w                           ),                   
    .t2r_wdat_w                        (t2r_a_wdat_w                           ),                   
    .t2r_rdy_w                         (1'b1                                   ),                  
    .t2r_rdat_w                        (t2r_a_rdat_w                           ),                   
    .t2r_intr_w                        (1'b0                                   )                   
    );

tm_ahb_if
   #(
    .ADDR_W                            (ADDR_W                                 ),
    .MODE_SEL                          (2                                      )                     
    )
u2_tm_ahb_if
    (
    .tai_clk_i                         (tbm_b_clk_i                            ),            
    .tai_rst_n_i                       (tbm_b_rst_n_i                          ),              
    .tai_haddr_i                       (tbm_b_haddr_i                          ),              
    .tai_hprot_i                       (tbm_b_hprot_i                          ),              
    .tai_hsel_i                        (tbm_b_hsel_i                           ),             
    .tai_hsize_i                       (tbm_b_hsize_i                          ),              
    .tai_htrans_i                      (tbm_b_htrans_i                         ),               
    .tai_hwdata_i                      (tbm_b_hwdata_i                         ),               
    .tai_hwrite_i                      (tbm_b_hwrite_i                         ),               
    .tai_hrdata_o                      (tbm_b_hrdata_o                         ),               
    .tai_hready_o                      (tbm_b_hready_o                         ),               
    .tai_hresp_o                       (tbm_b_hresp_o                          ),              
    .tai_t2r_intr_o                    (tbm_b_t2r_intr_o                       ),        

    .t2r_clk_w                         (t2r_b_clk_w                            ),                  
    .t2r_rst_n_w                       (t2r_b_rst_n_w                          ),                    
    .en_box                            (t2r_b_en_box                           ),                   
    .write_box                         (t2r_b_write_box                        ),                   
    .t2r_addr_w                        (t2r_b_addr_w                           ),                   
    .t2r_wdat_w                        (t2r_b_wdat_w                           ),                   
    .t2r_rdy_w                         (1'b1                                   ),                  
    .t2r_rdat_w                        (t2r_b_rdat_w                           ),                   
    .t2r_intr_w                        (1'b0                                   )                   
    );

sdpram
   #(
    .ADDR_W                            (ADDR_W                                 )
    )
u_sdpram
    (
    .a_clk_i                           (t2r_a_clk_w                            ),       
    .a_rst_n_i                         (t2r_a_rst_n_w                          ),         
    .a_en_i                            (t2r_a_en_box                           ),      
    .a_write_i                         (t2r_a_write_box                        ),         
    .a_addr_i                          (t2r_a_addr_w                           ),        
    .b_clk_i                           (t2r_b_clk_w                            ),       
    .b_rst_n_i                         (t2r_b_rst_n_w                          ),         
    .b_en_i                            (t2r_b_en_box                           ),      
    .b_addr_i                          (t2r_b_addr_w                           ),        
    .wdat_i                            (t2r_a_wdat_w                           ),      
    .a_rdat_o                          (t2r_a_rdat_w                           ),        
    .b_rdat_o                          (t2r_b_rdat_w                           )
    );
endmodule

